package com.codermn.demo6;

import java.io.IOException;
import java.util.Scanner;

/**
 * @author jxau_scf
 * @date 2021/6/17 - 19:40
 */
public class Test {
    static String[] userNames = {"张三","李四","王五"};
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String userName = scanner.next();
        checkUserName(userName);
    }

    private static void checkUserName(String userName) {
        for (String name : userNames) {
            if (name.equals(userName)) {
                try {
                    throw new RegisterException("该用户已被注册");
                }catch (RegisterException e){
                    e.printStackTrace();
                    return;
                }
            }
        }
        System.out.println("恭喜，注册成功！");
    }
}
